package cn.csxw.openchina.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import cn.csxw.openchina.interfaces.UIOperation;
import cn.csxw.openchina.utils.Global;

/**
 * 最普通的Fragment的基类
 */

public abstract class BaseFragment extends Fragment implements UIOperation {

    private View mRootView;
    protected AppCompatActivity mActivity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mActivity = (AppCompatActivity) getActivity();
        if (mRootView == null) {
/*            mRootView = Global.inflate(getLayoutRes());*/
            mRootView = mActivity.getLayoutInflater().inflate(getLayoutRes(),container,false);
            ButterKnife.bind(this, mRootView);
            Global.findButtonsAndSetOnClickListener(mRootView, this);
        }

        initView();
        initData();
        initListener();
        return mRootView;
    }

    @Override
    public void onClick(View v) {
        onClick(v, v.getId());
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ButterKnife.bind(this, mRootView).unbind();
    }
}
